#!/usr/bin/env python
# encoding: utf-8
"""
ThingsDates.py

Created by Christopher Glasman on 2009-04-22.
Copyright (c) 2009 Christopher Glasman. 

This file is part of thingsplot.

thingsplot is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

thingsplot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with thingsplot.  If not, see <http://www.gnu.org/licenses/>.

"""

import time
from matplotlib import dates

debug = False

def convert_things_date_to_pythonic(date_in_things_form):
    """Things date is float seconds since Jan 1st 2001. 
    Pythonic date takes unix epoch i.e. seconds since 1970. """
    date_in_pythonic_form = date_in_things_form + 31*365*24*60*60.0 + 8*24*60*60.0
    if(debug==True):
        print "things form: ", date_in_things_form, " which is: ", time.ctime(date_in_things_form)
        print "pythonic form: ", date_in_pythonic_form, " which is: ", time.ctime(date_in_pythonic_form)
    return date_in_pythonic_form

def convert_pythonic_date_to_things(date_in_pythonic_form):
    """Things date is float seconds since Jan 1st 2001. 
    Pythonic date takes unix epoch i.e. seconds since 1970. """
    date_in_things_form = date_in_pythonic_form - (31*365 +8)*24*60*60.0
    if(debug==True):
        print "pythonic form: ", date_in_pythonic_form, " which is: ", time.ctime(date_in_pythonic_form)
        print "things form: ", date_in_things_form, " which is: ", time.ctime(date_in_things_form)
    return date_in_things_form

def convert_pythonic_date_to_matplotlib(date_in_pythonic_form):
    pass


def pythonic_start_of_day(day):
    start_of_day = int(day/60.0/60.0/24)*60*60*24.0
    return start_of_day


def pythonic_hour_in_day(day, hour):
    startofday = pythonic_start_of_day(day)
    hour_in_day = startofday + hour*60.0*60.0
    return hour_in_day






